package rad.framework.uml2.uml.edit.providers.elementItemProvider.namedElement.nameSpace.classifier.behavioredClassifier;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.UseCase;

import rad.framework.uml2.uml.edit.UMLEditPlugin;
import rad.framework.uml2.uml.edit.providers.elementItemProvider.namedElement.nameSpace.classifier.BehavioredClassifierItemProvider;

public class UseCaseItemProvider
		extends BehavioredClassifierItemProvider
		implements IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource {

	public UseCaseItemProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	@Override
	public List getPropertyDescriptors(Object object) {
		if (itemPropertyDescriptors == null) {
			super.getPropertyDescriptors(object);

			addIncludePropertyDescriptor(object);
			addExtendPropertyDescriptor(object);
			addExtensionPointPropertyDescriptor(object);
			addSubjectPropertyDescriptor(object);
		}
		return itemPropertyDescriptors;
	}

	protected void addIncludePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_UseCase_include_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_UseCase_include_feature", "_UI_UseCase_type"),
				UMLPackage.Literals.USE_CASE__INCLUDE, true, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addExtendPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_UseCase_extend_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_UseCase_extend_feature", "_UI_UseCase_type"),
				UMLPackage.Literals.USE_CASE__EXTEND, true, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addExtensionPointPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_UseCase_extensionPoint_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_UseCase_extensionPoint_feature", "_UI_UseCase_type"),
				UMLPackage.Literals.USE_CASE__EXTENSION_POINT, true, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addSubjectPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_UseCase_subject_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_UseCase_subject_feature", "_UI_UseCase_type"),
				UMLPackage.Literals.USE_CASE__SUBJECT, true, null, null, null));
	}

	@Override
	public Collection getChildrenFeatures(Object object) {
		if (childrenFeatures == null) {
			super.getChildrenFeatures(object);
			childrenFeatures.add(UMLPackage.Literals.USE_CASE__INCLUDE);
			childrenFeatures.add(UMLPackage.Literals.USE_CASE__EXTEND);
			childrenFeatures.add(UMLPackage.Literals.USE_CASE__EXTENSION_POINT);
		}
		return childrenFeatures;
	}

	@Override
	protected EStructuralFeature getChildFeature(Object object, Object child) {

		return super.getChildFeature(object, child);
	}

	@Override
	public Object getImage(Object object) {
		return overlayImage(object, getResourceLocator().getImage("full/obj16/UseCase"));
	}

	@Override
	public String getText(Object object) {
		return appendLabel(appendType(appendKeywords(new StringBuffer(), object), "_UI_UseCase_type"), object).toString();
	}

	@Override
	public void notifyChanged(Notification notification) {
		updateChildren(notification);

		switch (notification.getFeatureID(UseCase.class)) {
			case UMLPackage.USE_CASE__INCLUDE:
			case UMLPackage.USE_CASE__EXTEND:
			case UMLPackage.USE_CASE__EXTENSION_POINT:
				fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
				return;
		}
		super.notifyChanged(notification);
	}

	@Override
	protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) {
		super.collectNewChildDescriptors(newChildDescriptors, object);

		newChildDescriptors.add(createChildParameter(UMLPackage.Literals.BEHAVIORED_CLASSIFIER__OWNED_BEHAVIOR, UMLFactory.eINSTANCE.createActivity()));

		newChildDescriptors.add(createChildParameter(UMLPackage.Literals.BEHAVIORED_CLASSIFIER__OWNED_BEHAVIOR, UMLFactory.eINSTANCE.createStateMachine()));

	}

	@Override
	public ResourceLocator getResourceLocator() {
		return UMLEditPlugin.INSTANCE;
	}

}
